package org.idea.spring.jdbc.xa;

import com.mysql.jdbc.Connection;

import java.sql.*;

/**
 * @Author linhao
 * @Date created in 6:39 下午 2021/11/3
 */
public class JdbcTimeOutDemo {

    public static String driver = "com.mysql.jdbc.Driver";
    public static String url = "jdbc:mysql://localhost:3306/test?useSSL=false&useUnicode=true&characterEncoding=UTF8&connectTimeout=6000&socketTimeout=6000";
    public static String username = "root";
    public static String password = "root";
    public static String sql = "select * from t_user";

    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        Class.forName(driver); //classLoader,加载对应驱动//(1)
        Connection conn = (Connection) DriverManager.getConnection(url, username, password);//进行链接(2)
        PreparedStatement preparedStatement = conn.prepareStatement(sql);
        ResultSet rs = preparedStatement.executeQuery();
        while (rs.next()){
            int i = rs.getInt(1);
            System.out.println(i);
        }
        conn.close();
    }
}
